home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / interapplication comm / 7edit / source / svaewindowutils.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-23  |  3.7 KB  |  165 lines

  1. /*
  2.     File:        SVAEWindowUtils.c
  3.  
  4.     Contains:    
  5.  
  6.     Written by: Original version by Jon Lansdell and Nigel Humphreys.
  7.                 3.1 updates by Greg Sutton.
  8.  
  9.     Copyright:    Copyright © 1995-1999 by Apple Computer, Inc., All Rights Reserved.
  10.  
  11.                 You may incorporate this Apple sample source code into your program(s) without
  12.                 restriction. This Apple sample source code has been provided "AS IS" and the
  13.                 responsibility for its operation is yours. You are not permitted to redistribute
  14.                 this Apple sample source code as "Apple sample source code" after having made
  15.                 changes. If you're going to re-distribute the source, we require that you make
  16.                 it clear in the source that the code was descended from Apple sample source
  17.                 code, but that you've made changes.
  18.  
  19.     Change History (most recent first):
  20.                             7/20/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  21.                 
  22.  
  23. */
  24.  
  25.  
  26. #include "SVAEWindowUtils.h"
  27.  
  28. #include "SVEditWindow.h"        // for DPtrFromWindowPtr()
  29.  
  30.  
  31.  
  32. #include <LowMem.h>
  33. #include <TextUtils.h>
  34.  
  35.  
  36.  
  37.  
  38. WindowPtr WindowNameToWindowPtr(StringPtr nameStr)
  39. /* 
  40.     Returns the WindowPtr of the window with title nameStr
  41.     or nil if there is no matching window.
  42. */
  43.     { 
  44.         WindowPtr theWindow;
  45.         Str255    windTitle;
  46.             
  47.         theWindow =(WindowPtr)LMGetWindowList();
  48.         /* 
  49.             iterate through windows - we use WindowList 'cos we could
  50.             have made the window invisible and  we lose it - so we
  51.             can't set it back to visible!!
  52.         */
  53.         while (theWindow)
  54.             {
  55.                 GetWTitle(theWindow, windTitle);
  56.                 if (EqualString(windTitle,
  57.                                 nameStr,
  58.                                                 false,
  59.                                                 true))     /* ignore case, don't ignore diacriticals */
  60.                     return(theWindow);
  61.               theWindow = (WindowPtr)((WindowPeek)theWindow)->nextWindow;
  62.             }
  63.         return(theWindow);
  64.     }    /* WindowNameToWindowPtr */
  65.  
  66.     
  67. OSErr    GetDescOfNamedWindow(StringPtr nameStr, AEDesc* result)
  68. {
  69.     WindowToken        theToken;
  70.     OSErr            err = noErr;
  71.     
  72.     theToken.tokenWindow = WindowNameToWindowPtr(nameStr);
  73.     
  74.     if (theToken.tokenWindow)
  75.         err = AECreateDesc(typeMyWndw, (Ptr)&theToken, sizeof(theToken), result);
  76.     else
  77.         err = errAENoSuchObject;
  78.  
  79.     return(err);
  80. }
  81.  
  82.  
  83. short CountWindows(void)
  84. {
  85.     WindowPtr theWindow;
  86.     short     index;
  87.             
  88.     index = 0;
  89.     theWindow = (WindowPtr)LMGetWindowList();
  90.  
  91.     // iterate through windows
  92.     while (theWindow)
  93.         {
  94.             index++;                    
  95.           theWindow = (WindowPtr)((WindowPeek)theWindow)->nextWindow;
  96.         }
  97.     
  98.     return(index);
  99. } // CountWindows
  100.  
  101.  
  102. WindowPtr GetWindowPtrOfNthWindow(short index)
  103. /* returns a ptr to the window with the given index
  104.   (front window is 1, behind that is 2, etc.).  if
  105.   there's no window with that index (inc. no windows
  106.   at all), returns nil.
  107. */
  108.   {
  109.       WindowPtr theWindow;
  110.         
  111.         theWindow = (WindowPtr)LMGetWindowList();
  112.     
  113.         /* iterate through windows */
  114.         
  115.         while (theWindow)
  116.             {
  117.                 index --;
  118.                 if (index <= 0) 
  119.                     return(theWindow);
  120.                     
  121.               theWindow = (WindowPtr)((WindowPeek)theWindow)->nextWindow;
  122.             }
  123.         return(nil);
  124.     }    /* GetWindowPtrOfNthWindow */
  125.     
  126. short    GetNthWindowOfWindowPtr(WindowPtr aWindow)
  127. // Given a WindowPtr this routine tries to find the
  128. // index to that window. If not found it will return
  129. // zero
  130. {
  131.     WindowPtr theWindow;
  132.     short     index;
  133.             
  134.     index = 0;
  135.     theWindow = (WindowPtr)LMGetWindowList();
  136.  
  137.         // iterate through windows
  138.     while (theWindow)
  139.     {
  140.         index++;
  141.         if (theWindow == aWindow)
  142.             return(index);
  143.                         
  144.         theWindow = (WindowPtr)((WindowPeek)theWindow)->nextWindow;
  145.     }
  146.     
  147.     return(0);
  148. } // GetNthWindowOfWindowPtr
  149.  
  150.  
  151. OSErr    GetDescOfNthWindow(short index, AEDesc* result)
  152. {
  153.     WindowToken        theToken;
  154.     OSErr            err = noErr;
  155.     
  156.     theToken.tokenWindow = GetWindowPtrOfNthWindow(index);
  157.     
  158.     if (theToken.tokenWindow)
  159.         err = AECreateDesc(typeMyWndw, (Ptr)&theToken, sizeof(theToken), result);
  160.     else
  161.         err = errAEIllegalIndex;
  162.  
  163.     return(err);
  164. }
  165.